package me.baicai.weixin.provider.controller;

import io.swagger.annotations.ApiOperation;
import me.baicai.weixin.application.Result;
import me.baicai.weixin.identity.repository.AdvertisingRepository;
import me.baicai.weixin.identity.service.AdverTisingService;
import me.baicai.weixin.provider.service.WeixinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class AdminController
{

    @Autowired
    private WeixinService weixinService;

    @Autowired
    private AdverTisingService adverTisingService;

    @ApiOperation("微信提现申请")
    @PostMapping("/weixin/applyWithdrawals")
    public Result applyWithdrawals(@RequestHeader("openid") String openid,@RequestParam("amount") float amount){
        return weixinService.applyWithdrawals(openid, amount);
    }

    @ApiOperation("admin微信提现查看")
    @PostMapping("/weixin/withdrawalRecord")
    public Result withdrawalRecord(@RequestHeader(value = "openid", required = false) String openid, @RequestParam(value = "value" , required = false) String value, @RequestParam("page") Integer page, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "status", required = false) String status){
        return weixinService.withdrawalRecord(openid,value,page,type,status);
    }

    @ApiOperation("admin微信提现审批")
    @PostMapping("/weixin/approvalWithdrawal")
    public Result approvalWithdrawal(@RequestHeader("openid") String openid,@RequestParam("id") Integer id, @RequestParam("type") String type){
        return weixinService.approvalWithdrawal(openid, id, type);
    }


    @ApiOperation("admin订单退款")
    @PostMapping("/weixin/refundOrder")
    public Result refundOrder(@RequestHeader("openid") String openid,@RequestParam("id") String id){
        return weixinService.refundOrder(openid, id);
    }


    @ApiOperation("admin广告列表")
    @PostMapping("/weixin/advertising")
    public Result advertising(){
        return adverTisingService.findAll();
    }

    @ApiOperation("admin广告列表开关")
    @PostMapping("/weixin/advertisingSet")
    public Result advertisingSet(@RequestParam("id") Integer id, @RequestParam("status") Integer status){
        return adverTisingService.advertisingSet(id, status);
    }

    @ApiOperation("所有设备查看")
    @PostMapping("/weixin/allDevice")
    public Result allDevice(@RequestParam("page") Integer page,@RequestParam(value = "sn",required = false) String sn){
        return weixinService.allDevice(page, sn);
    }


    @ApiOperation("提现手续费")
    @PostMapping("/weixin/rate")
    public Result getRate(){
        return weixinService.getRate();
    }
}
